package com.pug.service.category;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pug.mapper.category.CategoryMapper;
import com.pug.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * Author: lqm
 * create: 2022/5/15 10:04
 * Lover: lqx
 *
 * @see
 */
@Service
public class CategoryServiceImplPool extends ServiceImpl<CategoryMapper, Category> implements ICategoryService , Callable<List<Category>> {
    @Resource
    CategoryServiceImpl categoryService;
    String CATEGORY_REDIS_KEY = "pug:category:index";
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public List<Category> call() throws Exception {
        List<Category> redisList= (List<Category>)redisTemplate.opsForValue().get(CATEGORY_REDIS_KEY);
        if(redisList==null||redisList.size()==0){
            QueryWrapper<Category> queryWrapper=new QueryWrapper();
            queryWrapper.eq("status",1);
            List<Category> list = categoryService.list(queryWrapper);
            return list;
        }
        return redisList;
    }

    @Override
    public List<Category> findCategories() {
        return null;
    }
}
